package sort.impl;

import sort.BaseSort;

public class Selection implements BaseSort {
    @Override
    public void safeSort(Comparable[] arr) {
        if(arr == null || arr.length <2){
            return;
        }
        int len = arr.length;
        for(int i = 0; i < len - 1; i++){
            int minIndex = i;
            for(int j = i + 1; j < len; j ++){
                if(arr[minIndex].compareTo(arr[j]) > 0){
                    minIndex = j;
                }
            }
            if(minIndex != i){
                BaseSort.swap(arr, minIndex, i);
            }
        }
    }

}
